﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.UI;
using CMSMVC4.Filters;

namespace CMSMVC4.Areas.Main.Controllers
{
    public class DoiTacController : Controller
    {
        //
        // GET: /Main/DoiTac/

        [OutputCache(Duration = 900, VaryByParam = "id", Location = OutputCacheLocation.Client, NoStore = true)]
        public ActionResult Index()
        {
            if (ModelState.IsValid)
            {
                CMSMVC4Entities db = new CMSMVC4Entities();
                CommandSql cm = new CommandSql();
                var cate = cm.GetIdCategorieByStatus(MenuType.DoiTac, PageStatus.GioiThieu);
                if (cate.Rows.Count > 0)
                {
                    int id = Convert.ToInt32(cate.Rows[0]["Id"].ToString());
                    var data = cm.GetPageLang(id);
                    if (data.Rows.Count > 0)
                    {
                        ViewBag.Title = data.Rows[0]["Name"].ToString();
                        ViewBag.key = data.Rows[0]["Name"].ToString();
                        ViewBag.description = data.Rows[0]["Name"].ToString();
                        //ViewBag.IdPage = data.Rows[0]["PageId"].ToString();
                    }
                    //select menu dang chon
                    var menu = db.Menus.FirstOrDefault(x => x.Type == MenuType.DoiTac);
                    if (menu != null)
                    {
                        ViewBag.Menu = menu.Id;
                    }
                    else
                    {
                        ViewBag.Menu = 0;
                    }
                    return View(data);

                }
            }
            return View("Error");
        }

    }
}
